package com.vrv.vap.baseline.service.impl;

import com.vrv.vap.baseline.config.ExcelTemplateConfig;
import com.vrv.vap.baseline.entity.MyticketTemplate;
import com.vrv.vap.baseline.mapper.MyticketTemplateMapper;
import com.vrv.vap.baseline.service.AbstractExcelExportService;
import com.vrv.vap.baseline.util.FileOperationUtil;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.util.List;

@Service
public class MyticketTemplateExportService extends AbstractExcelExportService<MyticketTemplate> {
    private static final String key = "myticket";
    private final MyticketTemplateMapper myticketTemplateMapper;

    public MyticketTemplateExportService(FileOperationUtil fileOperationUtil, ExcelTemplateConfig excelTemplateConfig, MyticketTemplateMapper myticketTemplateMapper) {
        super(fileOperationUtil, excelTemplateConfig, key);
        this.myticketTemplateMapper = myticketTemplateMapper;
    }

    @Override
    protected List<MyticketTemplate> getAllData() {
        return myticketTemplateMapper.selectAll();
    }

    @Override
    protected void processData(List<MyticketTemplate> dataList, String format) throws IOException {
        for (MyticketTemplate template : dataList) {
            String formData = template.getFormData();
            if (formData != null && formData.length() > maxCellLength) {
                String fileName = template.getGuid() + ".txt";
                File file = fileOperationUtil.createFile(fileName, key, format);
                fileOperationUtil.writeContentToFile(file, formData);
                template.setFormData(fileName);
            }
        }
    }

    @Override
    protected Class<MyticketTemplate> getEntityClass() {
        return MyticketTemplate.class;
    }


}